#include "types.h"
#include "memlayout.h"

// UART 16550 register definitions
#define UART_THR 0    // Transmit Holding Register
#define UART_LSR 5    // Line Status Register
#define LSR_THRE (1<<5)  // Transmit Holding Register Empty

// Read/write UART registers
#define ReadReg(reg) (*(volatile uint8*)(UART0 + (reg)))
#define WriteReg(reg, v) (*(volatile uint8*)(UART0 + (reg)) = (v))

// Initialize UART (simplified version)
void uart_init(void) {
    // For minimal OS, we assume UART is already configured
    // In a real system, you would configure baud rate, etc.
}

// Output a single character to UART
void uart_putc(char c) {
    // Wait for transmit holding register to be empty
    while ((ReadReg(UART_LSR) & LSR_THRE) == 0) {
        // Busy wait
    }
    // Write character to transmit holding register
    WriteReg(UART_THR, c);
}

// Output a string to UART
void uart_puts(const char* str) {
    while (*str) {
        uart_putc(*str++);
    }
}
